<?php
$header = array(
	'Tên danh mục'=>'',
	'Chú thích'=>'', 
	'Code'=>'',
	'Games'=>'',

	);
$config = array(
    'header_icon' => @$this->resource->RES_ICON,
    'header_title' => 'Quản lý '.@$this->resource->RES_NAME,
    'add_title' => 'Thêm '.@$this->resource->RES_NAME,
    'ID' => '0',
    'showEdit' => false,
    'showDelete' => false,
    'showAdd' => false,
);
if ($this->permission->check("delete", $this->resource->RES_CODE))
    $config['showDelete'] = true;

if ($this->permission->check("update", $this->resource->RES_CODE))
    $config['showEdit'] = true;
	
if ($this->permission->check("insert", $this->resource->RES_CODE))
    $config['showAdd'] = true;

$data = array();
if ($datas) foreach ($datas as $cate) {
	if (!$cate || !isset($cate['parent']->cat_id)) 
		continue;
		
	$result =  (object) $cate['parent'];
	$data[] = array($result->{$this->{$this->model}->primaryKey}, "<b class='catparent'>".$result->cat_name. "</b>",$result->cat_description, $result->cat_code,$result->cat_count,);
	
	if (isset($cate['child']) && $cate['child']) {
		foreach ($cate['child'] as $child) {
			$child = (object) $child;
			$data[] = array($child->{$this->{$this->model}->primaryKey}, "<span class='catchild'> &nbsp;&nbsp;&nbsp;&nbsp;- " . $child->cat_name . "</span>",$child->cat_description, $child->cat_code,$child->cat_count,);
		}
	}
}

// foreach ($datas as $result) {
    // $data[] = array($result->{$this->{$this->model}->primaryKey},$result->cat_name,$result->cat_description, $result->cat_code,$result->cat_count,);
// }

echo $this->atheme->table_simple($header, $data, $config);

?>

<script> 
$(function (){
	$('.catparent').parents('tr').attr('data-parent', "1");
	$('tr[data-parent]').click(function (){
		var un ;
		$('tr:not([data-parent])').hide();
		e  = $(this).next();
		while (!$(e).attr('data-parent')){
			console.log(e);
			$(e).show('fast');
			e = $(e).next();
		}
	});
	$('tr:not([data-parent])').hide();
});

</script>
<style> 
[data-parent] {
	cursor: pointer;
}
</style>
